$(function(){
	$("#publishBtn").click(publish);
});

function publish() {
	$("#publishModal").modal("hide");

	//发送ajax请求前，将csrf令牌存到请求头
	// var token = $("meta[name='_csrf']".attr("content"));
	// var header = $("meta[name='_csrf_header']".attr("content"));
	// $(document).ajaxSend(function (e, xhr, options){
	// 	xhr.setRequestHeader(header, token)
	// });

	var title = $("#recipient-name").val();
	var content = $("#message-text").val();
	$.post(
		CONTEXT_PATH + "/discuss/add",
		{"title": title, "content": content},
		function (data){
			data = $.parseJSON(data);
			$("#hintBody").text(data.msg);

			//显示消息提示
			$("#hintModal").modal("show");
			setTimeout(function(){
				$("#hintModal").modal("hide");
				//成功时刷新页面
				if(data.code == 0){
					window.location.reload();
				}
			}, 2000);
		}
	)

}